package in.muton.edushare.pages;

import in.muton.edushare.panels.userfeedback.FeedbackFormPanel;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.HeaderContributor;
import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.JavascriptPackageResource;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.markup.html.panel.Panel;

public class FooterLinks extends Panel {
	
	private static final long serialVersionUID = 6264484107057186080L;
	private Panel formPH; //form place-holder for feedback
	
	public FooterLinks(String id){
		this(id, null);
	}
	
	/**
	 * CSS Structure is<br/>
	 * &lt;div&gt;<br/>
			 &lt;div id="ufeedbackall" class="ufeedbackall"&gt;<br/>
	        	&lt;div style="width:750px;" class="clearfix"&gt;<br/>
	        		&lt;span style="float:right;background-color:red;padding:5px 3px;"&gt;<br/>
	        			&lt;a style="color:yellow; font-weight:bold;" id="closeufb" href="#"&gt;Close&lt;/a&gt;<br/>
	        		&lt;/span&gt;<br/>
	        	&lt;/div&gt;<br/>
	        	&lt;div wicket:id="formPH"&gt;form goes here!&lt;/div&gt;<br/>
	        &lt;/div&gt;<br/>
	        &lt;ul class="es-horMenu"&gt;<br/>
				&lt;li&gt;<br/>
					&lt;a href="http://muton.in"&gt;&copy;&nbsp;2010&nbsp;Muton&lt;/a&gt;<br/>
				&lt;/li&gt;<br/>
			&lt;/ul&gt;<br/>
		&lt;/div&gt;<br/>
		
	 * @param id
	 * @param cssHeaderForLinks
	 */
	public FooterLinks(String id, HeaderContributor cssHeaderForLinks) {
		super(id);
		if(cssHeaderForLinks==null)
			add(CSSPackageResource.getHeaderContribution(FooterLinks.class, "FooterLinks.css"));
		else
			add(cssHeaderForLinks);

		add(JavascriptPackageResource.getHeaderContribution(FooterLinks.class, "FooterLinks.js"));
		final WebMarkupContainer feedbackPanelCont = new WebMarkupContainer("ufeedbackall");
		feedbackPanelCont.setOutputMarkupPlaceholderTag(true);
		feedbackPanelCont.setMarkupId("ufeedbackall");
		add(feedbackPanelCont);
		formPH = new EmptyPanel("formPH"); 
		feedbackPanelCont.add(formPH);
		
//		final FeedbackFormPanel bugPanel = new FeedbackFormPanel("formPH", "Bug");
		AjaxLink<Void> reportBug = new AjaxLink<Void>("reportBug") {
			private static final long serialVersionUID = 522260144921147234L;

			@Override
			public void onClick(AjaxRequestTarget target) {
				FeedbackFormPanel bugPanel = new FeedbackFormPanel("formPH", "Bug");
				formPH.replaceWith(bugPanel);
				formPH = bugPanel;
				target.addComponent(feedbackPanelCont);
			}
		};
		reportBug.setOutputMarkupId(true);
		reportBug.setMarkupId("reportBugBug");
		add(reportBug);
		
		AjaxLink<Void> reportFeedback = new AjaxLink<Void>("reportfns") {

			private static final long serialVersionUID = 8708334324330221825L;

			@Override
			public void onClick(AjaxRequestTarget target) {
				FeedbackFormPanel feedbackPanel = new FeedbackFormPanel("formPH", "Feedback");
				formPH.replaceWith(feedbackPanel);
				formPH = feedbackPanel;
				target.addComponent(feedbackPanelCont);
			}
			
		};
		reportFeedback.setOutputMarkupId(true);
		reportFeedback.setMarkupId("reportBugFS");
		add(reportFeedback);
	
	}

}
